package com.example.liunanxin.lnx226ordering.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.liunanxin.lnx226ordering.R;
import com.example.liunanxin.lnx226ordering.beans.FoodCommentsBean;

import java.util.List;

public class FoodCommentsAdapter extends RecyclerView.Adapter<FoodCommentsAdapter.ItemViewHolder> {

    private List<FoodCommentsBean> foodCommentsBeans;

    public void setData(List<FoodCommentsBean>foodCommentsBeans){
        this.foodCommentsBeans=foodCommentsBeans;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_food_comments,viewGroup,false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder itemViewHolder, int i) {
        FoodCommentsBean foodCommentsBean=foodCommentsBeans.get(i);
        final int positon=1;
        itemViewHolder.tv_comment.setText(foodCommentsBean.getContent());
        itemViewHolder.tv_time.setText(foodCommentsBean.getComment_time());
    }

    @Override
    public int getItemCount() {
        return foodCommentsBeans==null?0:foodCommentsBeans.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {

        TextView tv_comment,tv_time;
        View itemview;

        public ItemViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_comment=itemView.findViewById(R.id.textView18);
            tv_time=itemView.findViewById(R.id.textView21);
            this.itemview=itemView;

        }
    }
}
